<template>
	<view>
		<view class="conent_box">
			<view class="conent">
				<view class="conent_text">
					<!-- <text>团队终端状态统计</text> -->
					<u-search placeholder="输入SN号搜索" v-model="search" :clearabled="true" :showAction="false"
						bgColor="#f5f5f5" class="search" @search="_search()" @clickIcon="_search()">
					</u-search>
					<u-action-sheet :actions="stateData" @select="selectClick" :show="show" cancelText="取消" @close="_close">
					</u-action-sheet>
					<text class="status" @click="show = true">状态查询</text>
				</view>
				<view class="conent_cont">
					<view class="list_box" v-if="display == true">
						<view class="list" v-for="(item,index) in data.data" :key="index" @click="info(item.id,item.sn)">
							<view class="list_top">
								<text class="SN">SN：{{item.sn}}</text>
								<view class="copy">
									<text class="copy_1" @click.stop="copy(item.sn)">复制</text>
									<u-icon name="arrow-right" color="#999999" size="12"></u-icon>
								</view>
							</view>
							<view class="screen_list">
								<text v-if="item.is_active == 2"
									style="background-color: #2f9fff;color: #fff;">已激活</text>
								<text v-else style="background-color: #f26868;color: #fff;">未激活</text>
								<text v-if="item.is_bind == 2"
									style="background-color: #2f9fff;color: #fff;">已绑定</text>
								<text v-else style="background-color: #f26868;color: #fff;">未绑定</text>
							</view>
							<text class="belong">终端归属：{{item.agent_name}}-[{{item.agent_phone}}]</text>
						</view>
					</view>
					<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
					</u-empty>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {},
				page: 1,
				bottom: true,
				search: '',
				status: 0,
				id: null,
				stateData: [],
				show: false,
				search_type: false,
				display: null
			}
		},
		onLoad(e) {
			this.id = e.id
			if (e.type != undefined && e.type > 0) {
				this.status = e.type
			}
			this.getTerminalState()
			this._other()
			let Obj = new Object
		},
		//上拉加载
		onReachBottom() {
			if (this.bottom == true) {
				this.page += 1
				this._other()
			}
		},
		methods: {
			selectClick(index) {
				this.status = index.type
				this.search_type = true
				this.page = 1
				this.bottom = true
				this.search = ''
				this._other()
				this.show = false
			},
			_close() {
				this.show = false
			},
			// 回车搜索
			_search() {
				this.search_type = true
				this.page = 1
				this.bottom = true
				this._other()
			},
			// 终端状态
			async getTerminalState() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getTerminalState'
				});
				if (res.code == 200) {
					this.stateData = res.data
				}
			},
			// 页面数据展示
			async _other() {
				uni.showLoading({
					title: '加载中'
				});
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getEquipList',
					data: {
						page_size: 15,
						page: this.page,
						sn: this.search,
						status: this.status,
						product_id: this.id
					},
				});
				if (res.code == 200) {
					if (this.search_type) {
						if (res.data.data !== undefined && res.data.data !== null && res.data.data.length >
							0) {
							if (this.page == 1) {
								this.data = res.data
								this.display = true
								uni.hideLoading()
							} else {
								this.data.data = [...this.data.data, ...res.data.data]
								uni.hideLoading()
								this.display = true
							}
						} else {
							if (this.page == 1) {
								uni.hideLoading()
								this.bottom = false
								this.display = false
							} else {
								uni.hideLoading()
								this.bottom = false
								this.display = true
							}
						}
					} else {
						if (res.data.data !== undefined && res.data.data !== null && res.data.data.length >
							0) {
							if (this.page == 1) {
								this.data = res.data
								this.display = true
								uni.hideLoading()
							} else {
								this.data.data = [...this.data.data, ...res.data.data]
								this.display = true
								uni.hideLoading()
							}
						} else {
							if (this.page == 1) {
								uni.hideLoading()
								this.bottom = false
								this.display = false
							} else {
								uni.hideLoading()
								this.bottom = false
								this.display = true
							}
						}
					}
				} else {
					uni.showToast({
						title: res.msg,
						duration: 1000,
						icon: "none"
					});
					this.bottom = false
					this.display = false
				}
			},
			copy(e) {
				uni.setClipboardData({
					data: e,
					success: function() {}
				});
			},
			info(id, sn) {
				uni.navigateTo({
					url: '/pages/index/manage/manage_detail?id=' + id + '&sn=' + sn
				})
			}
		}
	}
</script>

<style lang="scss">
	.conent_box {
		// background-color: #f6f6f6;

		.conent {
			border-radius: 10rpx;
			// background-color: #fff;
			overflow: hidden;

			.conent_text {
				display: block;
				width: 100%;
				background-color: #2f9fff;
				padding: 20rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;

				text {
					color: #fff;
					font-size: 24rpx;
				}

				.status {
					border: #fff 1px solid;
					padding: 10rpx 15rpx;
					border-radius: 15rpx;
				}

				.search {
					width: 75%;
					flex: none;
					font-size: 28rpx;
				}
			}

			.conent_cont {
				// background-color: #fff;
				padding: 30rpx;

				.conent_tit {
					display: flex;
					align-items: center;
					justify-content: center;
					margin: 20rpx 0;

					text {
						font-size: 28rpx;
						color: #333333;
						margin-right: 20rpx;
					}
				}

				h1 {
					text-align: center;
					font-weight: 500;
					font-size: 38rpx;
					margin-bottom: 30rpx;
				}


			}
		}
	}

	.screen_top {
		display: flex;
		justify-content: space-between;
		padding: 25rpx;
		font-size: 28rpx;
		color: #333;
	}

	.list_box {
		box-sizing: border-box;

		.list {
			margin-bottom: 30rpx;
			box-sizing: border-box;
			background-color: #fff;
			padding: 30rpx 20rpx;

			.list_top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 30rpx;

				.SN {
					font-size: 32rpx;
					color: #333;
				}

				.copy {
					display: flex;
					align-items: center;

					.copy_1 {
						padding: 10rpx 35rpx;
						font-size: 24rpx;
						border: #1296db solid 1px;
						border-radius: 100rpx;
						margin-right: 15rpx;
						color: #1296db;
					}
				}
			}

			.screen_list {
				display: flex;
				flex-wrap: wrap;
				margin-bottom: 30rpx;

				text {
					background-color: #f6f6f6;
					color: #333;
					font-size: 24rpx;
					padding: 15rpx;
					text-align: center;
					margin-right: 15rpx;
					border-radius: 10rpx;
				}
			}

			.belong {
				padding: 20rpx 0 0 0;
				font-size: 28rpx;
				border-top: #f6f6f6 1px solid;
				display: block;
			}
		}
	}
</style>